/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of The Qt Company Ltd nor the names of its
**     contributors may be used to endorse or promote products derived
**     from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "sortingbox.h"

#include <QMouseEvent>
#include <QIcon>
#include <QPainter>
#include <QRandomGenerator>
#include <QStyle>
#include <QToolButton>
#include <QToolTip>
#include <QDir>
#include <QStringList>
#include <QAction>
#include <QMenu>

#define PADDING     6
#define PADDING_TOP 6

//! [0]
SortingBox::SortingBox(QWidget *parent,CSql* sql)
    : QWidget(parent),m_enable(false),m_Sql(sql)
{

    connect(this,SIGNAL(SetTitle(QString,QString)),this,SLOT(OnSetTitle(QString,QString)));
//! [0] //! [1]
    setMouseTracking(true);
//! [1] //! [2]
    setBackgroundRole(QPalette::Base);
//! [2]

    itemInMotion = nullptr;

//! [3]

    newPictureButton = createToolButton(_("New Picture"),
                                       QIcon(":/images/Picture.png"),
                                       SLOT(createNewCircle()));

    newSquareButton = createToolButton(_("New Pin"),
                                       QIcon(":/images/Pin.png"),
                                       SLOT(createNewSquare()));

    newDeleteButton = createToolButton(_("New Delete"),
                                         QIcon(":/images/Erase.png"),
                                         SLOT(createNewDelete()));

    newSaveButton = createToolButton(_("New Save"),
                                         QIcon(":/images/Save.png"),
                                         SLOT(createNewSave()));

    newOpenButton = createToolButton(_("New Open"),
                                         QIcon(":/images/Open.png"),
                                         SLOT(createNewOpen()));

    newCreateButton = createToolButton(_("New Create"),
                                         QIcon(":/images/New.png"),
                                         SLOT(createNewCreate()));

    newLayerButton = createToolButton(_("Select Layer"),
                                    QIcon(":/images/Layers.png"),
                                    SLOT(selectLayer()));


    newCreateButton->hide();
    //CreateLayerButton();

    newPictureButton->setEnabled(false);
    newSquareButton->setEnabled(false);
    newDeleteButton->setEnabled(false);
    newSaveButton->setEnabled(false);
    newLayerButton->setEnabled(false);


    //circlePath.addEllipse(QRect(0, 0, 300, 200));
    circlePath.addRect(QRect(0, 0, 400, 300));
/*
    squarePath.addRect(QRect(0, 0, 160, 60));
    squarePath.moveTo(0 ,30);
    squarePath.lineTo(160, 30);
    squarePath.moveTo(80 ,30);
    squarePath.lineTo(80, 60);
    */
    int w = 180,h=60;
    squarePath.addRect(QRect(0, 0, w, h));
    //squarePath.moveTo(0 ,h/2);
    //squarePath.lineTo(w, h/2);
    //squarePath.moveTo(w/2 ,h/2);
    //squarePath.lineTo(w/2, h);

    qreal x = trianglePath.currentPosition().x();
    qreal y = trianglePath.currentPosition().y();
    trianglePath.moveTo(x + 120 / 2, y);
    trianglePath.lineTo(0, 100);
    trianglePath.lineTo(120, 100);
    trianglePath.lineTo(x + 120 / 2, y);

//! [3] //! [4]
    //setWindowTitle(tr("Car "));
    resize(500, 300);

    //createShapeItem(circlePath, tr("Circle"), initialItemPosition(circlePath),
    //                initialItemColor(),E_BITMAP);
    //createShapeItem(squarePath, tr("Square"), initialItemPosition(squarePath),
    //                initialItemColor());
    //createShapeItem(trianglePath, tr("Triangle"),
    //                initialItemPosition(trianglePath), initialItemColor());



    //test();
}
//! [4]

//! [5]
bool SortingBox::event(QEvent *event)
{
//! [5] //! [6]
    if (event->type() == QEvent::ToolTip) {
        QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
        int index = itemAt(helpEvent->pos());
        if (index != -1) {
            QToolTip::showText(helpEvent->globalPos(), shapeItems[index].toolTip());
        } else {
            QToolTip::hideText();
            event->ignore();
        }

        return true;
    }
    return QWidget::event(event);
}
//! [6]

//! [7]
void SortingBox::resizeEvent(QResizeEvent * /* event */)
{
    int margin = style()->pixelMetric(QStyle::PM_DefaultTopLevelMargin);
    int x = 10; //margin;
    int y = 10;// margin;
    x = updateButtonGeometryX(newOpenButton, x, y);
    x = updateButtonGeometryX(newSaveButton, x, y);
    x = updateButtonGeometryX(newDeleteButton, x, y);
    x = updateButtonGeometryX(newSquareButton, x, y);
    x = updateButtonGeometryX(newPictureButton, x, y);
    x = updateButtonGeometryX(newLayerButton, x , y);

    /*
    int margin = style()->pixelMetric(QStyle::PM_DefaultTopLevelMargin);
    int x = width() - margin;
    int y = height() - margin;

    QSize size = newLayerButton->sizeHint();
    //button->setGeometry(x - size.rwidth(), y - size.rheight(),
    //                    size.rwidth(), size.rheight());
    //updateButtonGeometry(newLayerButton, x - size.rwidth()-margin, y);
    y = updateButtonGeometry(newLayerButton, x , y);
    y = updateButtonGeometry(newPictureButton, x, y);
    y = updateButtonGeometry(newSquareButton, x, y);
    y = updateButtonGeometry(newDeleteButton, x, y);
    y = updateButtonGeometry(newSaveButton, x, y);
    y = updateButtonGeometry(newOpenButton, x, y);
    //y = updateButtonGeometry(newCreateButton, x, y);
*/

}
//! [7]

//! [8]
void SortingBox::paintEvent(QPaintEvent * /* event */)
{
    /*
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    for (const ShapeItem &shapeItem : qAsConst(shapeItems)) {
//! [8] //! [9]
        painter.translate(shapeItem.position());
//! [9] //! [10]
//!
        if(itemInMotion == &shapeItem){
            painter.setBrush(Qt::NoBrush);
            painter.drawRect(shapeItem.path().controlPointRect());
        }
        painter.setBrush(shapeItem.color());
        painter.drawPath(shapeItem.path());

        painter.translate(-shapeItem.position());
    }
*/
    ///

    QPixmap pix = QPixmap(size());//新建pixmap
    QPixmap pixPP;// = QPixmap(("./images/car.png"));//新建pixmap
    QDir dir;

    //QString currentPath=dir.currentPath();
    //currentPath += "/images/car.png";
    //qDebug() << currentPath;
    //pixPP = QPixmap(currentPath);//新建pixmap

    //pix.fill(Qt::white);//背景色填充为白色
    pix.fill(QColor(qRgb(0x1b,0x1b,0x1b)));//背景色填充为白色
    QPainter p(&pix);//将_pixmap作为画布
    p.setRenderHint(QPainter::Antialiasing);
    QString sPos;
    for (const ShapeItem &shapeItem : qAsConst(shapeItems)) {

        p.translate(shapeItem.position());

        if(itemInMotion == &shapeItem){
            //p.setBrush(Qt::NoBrush);
            p.setPen(Qt::yellow);
            //p.drawRect(shapeItem.path().controlPointRect());
        }
        else{
            //p.drawRect(shapeItem.path().controlPointRect());
             //p.setPen(Qt::white);
             p.setPen(QColor::fromRgb(0x1b,0x1b,0x1b));
        }

        if(((ShapeItem)shapeItem).getShapType() != E_BITMAP){

            //title
            //p.setPen(Qt::NoPen);
            p.drawRect(shapeItem.path().controlPointRect());

            //p.setBrush(shapeItem.color());
            p.setBrush(QColor::fromRgb(255,255,255));
            p.drawPath(shapeItem.path());
            //
            QPainter painter(this);
            QFont font = painter.font();
            font.setFamily("NSimSun");
            font.setPixelSize(24);
            p.setFont(font);

            //const QRect rectangle = QRect(0, 0, 100, 50);
            //QRect boundingRect;
            //p.setPen(Qt::black);
            //p.setBrush(QColor::fromRgb(255,0,0));
            //p.drawText(rectangle, 0, tr("Hello"), &boundingRect);
            //p.drawText(shapeItem.path().controlPointRect().x(), Qt::AlignCenter, tr("Qt\nProject"));
            //p.drawText(shapeItem.path().controlPointRect().x()+5,shapeItem.path().controlPointRect().y()+22, tr("S310a_R_492"));

            p.setPen(QColor::fromRgb(60,60,60));
            p.drawText(shapeItem.path().controlPointRect().x()+5+20,shapeItem.path().controlPointRect().y()+22, ((ShapeItem)shapeItem).getPoint());
            font.setPixelSize(18);
            p.setFont(font);

            //Gap color
            p.setBrush(shapeItem.getGapColor());
            //p.setPen(Qt::white);
            p.setPen(Qt::NoPen);
            p.drawRect(shapeItem.path().controlPointRect().x(),
                       shapeItem.path().controlPointRect().y()+30,
                       shapeItem.path().controlPointRect().width()/2,
                       shapeItem.path().controlPointRect().height()/2);
            p.fillRect(shapeItem.path().controlPointRect().x(),
                       shapeItem.path().controlPointRect().y()+30,
                       shapeItem.path().controlPointRect().width()/2,
                       shapeItem.path().controlPointRect().height()/2, shapeItem.getGapColor());



            //p.setPen(Qt::black);
            p.setPen(QColor::fromRgb(60,60,60));
            sPos = "G:"+shapeItem.getGap();// QString("X:%1").arg(shapeItem.position().x());
            //p.setPen(shapeItem.getGapColor());
            p.drawText(shapeItem.path().controlPointRect().x()+5,shapeItem.path().controlPointRect().y()+22+30, sPos);
            p.setPen(Qt::NoPen);

            //flush color
            //p.setBrush(shapeItem.getFlushColor());
            //p.setPen(Qt::white);
            p.drawRect(shapeItem.path().controlPointRect().x()+90,
                       shapeItem.path().controlPointRect().y()+30,
                       shapeItem.path().controlPointRect().width()/2,
                       shapeItem.path().controlPointRect().height()/2);
            p.fillRect(shapeItem.path().controlPointRect().x()+90,
                       shapeItem.path().controlPointRect().y()+30,
                       shapeItem.path().controlPointRect().width()/2,
                       shapeItem.path().controlPointRect().height()/2, shapeItem.getFlushColor());
            //p.setPen(Qt::black);
            p.setPen(QColor::fromRgb(60,60,60));
            sPos = "F:"+shapeItem.getFlush();// QString("Y%1").arg(shapeItem.position().y());
            //p.setPen(shapeItem.getFlushColor());
            p.drawText(shapeItem.path().controlPointRect().x()+5+90,shapeItem.path().controlPointRect().y()+22+30, sPos);
            //p.setPen(Qt::NoPen);
            //
        //}
        //if(((ShapeItem)shapeItem).getShapType() != E_BITMAP){
            QPen pen = p.pen();
            pen.setColor(QColor::fromRgb(230,127,127));
            pen.setWidth(3);//改变线宽
            p.setPen(pen); //就可以画粗细了。
            if(shapeItem.arrowPosition().x()<= 80 && shapeItem.arrowPosition().y()<=30)
                p.drawLine(shapeItem.arrowPosition(),QPoint(0,0));
            else if(shapeItem.arrowPosition().x()> 80 && shapeItem.arrowPosition().y()<=30)
                p.drawLine(shapeItem.arrowPosition(),QPoint(180,0));
            else if(shapeItem.arrowPosition().x()<=80 && shapeItem.arrowPosition().y()>30)
                p.drawLine(shapeItem.arrowPosition(),QPoint(0,60));
            else if(shapeItem.arrowPosition().x()>80 && shapeItem.arrowPosition().y()>30)
                p.drawLine(shapeItem.arrowPosition(),QPoint(180,60));

            p.setPen(Qt::NoPen);
            //p.setBrush(Qt::red);
            p.setBrush(Qt::green);
            p.drawRect(shapeItem.ArrowRect());
            //
            pixPP = QPixmap(":/images/1F4CC.png");
            p.setPen(Qt::NoPen);
            p.setBrush(Qt::NoBrush);
            pixPP.scaled(22,22,
                         Qt::KeepAspectRatio, Qt::SmoothTransformation);
            p.drawPixmap(3,3,22,22,pixPP);

            //

        }
        else{
            //QBitmap 图片背景透明
             pixPP = QPixmap(((ShapeItem)shapeItem).getPic());
            //((ShapeItem)shapeItem).setPic(currentPath);
            p.setPen(Qt::NoPen);
            p.setBrush(Qt::NoBrush);
            if(pixPP.isNull()){
                pixPP.scaled(shapeItem.path().controlPointRect().width(),shapeItem.path().controlPointRect().height(),
                             Qt::KeepAspectRatio, Qt::SmoothTransformation);
                p.drawPixmap(0,0,shapeItem.path().controlPointRect().width(),shapeItem.path().controlPointRect().height(),pixPP);
            }
            else{
                pixPP.scaled(pixPP.width()>800?800:pixPP.width(),
                             pixPP.height()>600?600:pixPP.height(),
                             Qt::KeepAspectRatio, Qt::SmoothTransformation);
                p.drawPixmap(0,0,
                             pixPP.width()>800?800:pixPP.width(),
                             pixPP.height()>600?600:pixPP.height(),
                             pixPP);
            }
/*
            if(itemInMotion == &shapeItem){
                p.setPen(Qt::yellow);
            }
            else{
                 p.setPen(QColor::fromRgb(0x1b,0x1b,0x1b));
            }
            p.drawRect(QRect(0, 0, pixPP.width(), pixPP.height()));
            */
        }
        p.setPen(Qt::black);

        if(itemInMotion == &shapeItem){
            //p.setBrush(Qt::NoBrush);
            p.setPen(Qt::yellow);
            //p.drawRect(shapeItem.path().controlPointRect());
        }
        else{
            //p.drawRect(shapeItem.path().controlPointRect());
             //p.setPen(Qt::white);
             p.setPen(QColor::fromRgb(0x1b,0x1b,0x1b));
        }

        //if(((ShapeItem)shapeItem).getShapType() != E_BITMAP){
            p.drawRect(shapeItem.path().controlPointRect());
        //}


        p.translate(-shapeItem.position());


    }



    p.end();
    p.begin(this);//将当前窗体作为画布
    p.drawPixmap(0,0, pix);//将pixmap画到窗体




}
//! [10]

//! [11]
void SortingBox::mousePressEvent(QMouseEvent *event)
{

    if (event->button() == Qt::LeftButton) {
        setFocus();

        if(m_enable) {itemInMotion=nullptr;return;}

        int index = itemAt(event->pos());
        if (index != -1) {

            previousPosition = event->pos();
            if(shapeItems[index].getShapType() == E_BITMAP){
                shapeItems.move(index, 0);
                itemInMotion = &shapeItems[0];
            }
            else{
                shapeItems.move(index, shapeItems.size() - 1);
                itemInMotion = &shapeItems[shapeItems.size() - 1];
            }
            update();
        }
        else
            itemInMotion = nullptr;
        update();
    }


}
//! [11]

//! [12]
void SortingBox::mouseMoveEvent(QMouseEvent *event)
{
    QPoint gloPoint = event->pos();

    if(m_enable) return;


    if ((event->buttons() & Qt::LeftButton) && itemInMotion)
        moveItemTo(event->pos());
    else
        region(gloPoint);




    ///

}
//! [12]

//! [13]
void SortingBox::mouseReleaseEvent(QMouseEvent *event)
{
    if(m_enable) return;

    if (event->button() == Qt::LeftButton && itemInMotion) {
        moveItemTo(event->pos());
        //itemInMotion = nullptr;
    }

}
//! [13]
void SortingBox::keyPressEvent(QKeyEvent *event)
{
    if(event->key() ==Qt::Key_F12 && m_enable)
    {
         emit ShowHideDock1(false);
        this->setWindowFlags (Qt::Window);
        this->showFullScreen();
        setButtonShow(false);

    }
    if(event->key() == Qt::Key_Escape && m_enable)
    {
        //退出全屏时：
        this->setWindowFlags (Qt::SubWindow);
        this->showNormal ();
        emit ShowHideDock1(true);
        setButtonShow(true);
    }

    if(m_enable) return;

    if(event->key() == Qt::Key_Delete)              // 是否按下del键
    {
        createNewDelete();
    }

}
//! [14]
void SortingBox::createNewCircle()
{
    static int count = 1;
    createShapeItem(circlePath, tr("Circle <%1>").arg(++count),
                    randomItemPosition(), randomItemColor(),E_BITMAP);
}
//! [14]

//! [15]
void SortingBox::createNewSquare()
{
    static int count = 1;
    createShapeItem(squarePath, tr("Square <%1>").arg(++count),
                    randomItemPosition(), randomItemColor());
}
//! [15]

//! [16]
void SortingBox::createNewDelete()
{
    //static int count = 1;
    //createShapeItem(trianglePath, tr("Triangle <%1>").arg(++count),
    //                randomItemPosition(), randomItemColor());
    if(itemInMotion != nullptr){
        if(itemInMotion->getShapType() == E_BITMAP)
            shapeItems.erase(shapeItems.begin());
        else
            shapeItems.remove(shapeItems.size()-1);
        itemInMotion = nullptr;
        update();
    }
}
//! [16]
void SortingBox::createNewSave()
{
    int cnt = shapeItems.size();
    QString sql;
    neb::CJsonObject shapecjs,cjs;
    if(cnt>0){
        shapecjs.AddEmptySubArray("shape");
        for(int i=0;i<cnt;i++){
            cjs.Clear();
            //QString tmp = QString("%1,%2").arg(shapeItems[i].path().controlPointRect().width()).arg(shapeItems[i].path().controlPointRect().height());
            cjs.Add("w",(int)shapeItems[i].path().controlPointRect().width());
            cjs.Add("h",(int)shapeItems[i].path().controlPointRect().height());
            cjs.Add("P1_x",shapeItems[i].position().x());
            cjs.Add("P1_y",shapeItems[i].position().y());
            cjs.Add("P2_x",shapeItems[i].arrowPosition().x());
            cjs.Add("P2_y",shapeItems[i].arrowPosition().y());
            cjs.Add("type",shapeItems[i].getShapType());
            if(shapeItems[i].getShapType() == E_BITMAP){
                //cjs.Add("pic",shapeItems[i].getPic().toStdString());
                std::string pic = shapeItems[i].getPic().toUtf8().data();
                cjs.Add("pic",pic);
            }
            else
                cjs.Add("point",shapeItems[i].getPoint().toStdString());
            //qDebug()<<cjs.ToString().c_str();

            shapecjs["shape"].Add(cjs);

            //qDebug()<<tmp;
        }
        sql = QString("update fslayer set para = '%1' where value = '%2' and fsapp = '%3';")
                .arg(shapecjs.ToString().c_str())
                .arg(m_LayerName)
                .arg(m_ProjectName);
        qDebug()<<shapecjs.ToString().c_str();
        qDebug()<<sql.toStdString().c_str();
        m_Sql->exeSql(sql.toStdString());
    }
    else{
        //QMessageBox box(QMessageBox::Warning,"警告","工程图元为空，不能保存！");
        //box.setStandardButtons (QMessageBox::Ok|QMessageBox::Cancel);
        //box.setStandardButtons (QMessageBox::Ok);
        //box.setButtonText (QMessageBox::Ok,QString("确 定"));
        //box.setButtonText (QMessageBox::Cancel,QString("取 消"));
        //box.exec();
        MSGINF::MsgShowOk(this,_("Warning"),_("Measure Is Empty,Can't Save."));

    }

}
void SortingBox::createNewOpen()
{
    bool ok = false;
    QStringList items;
    NODE nd;
    NODE rds;
    std::string value;
    items << tr("Spring") << tr("Summer") << tr("Fall") << tr("Winter");
    items.clear();
    RECORDSET rd = m_Sql->RecordSet("select b.* from fsapp a,fslayer b where a.value = b.fsapp and b.value = 'default'");


    if(rd.size()>0){
        for(RECORDSET::iterator it = rd.begin();it!=rd.end();it++){
        //for(int i = 0;i<rd.size();i++){
            nd =  *it;
            value = nd["fsapp"];
            items << QString::fromLocal8Bit(value.c_str());
            rds[value] = nd["para"];
            qDebug() << QString::fromLocal8Bit(value.c_str());
        }
    }
    else{
        QMessageBox box(QMessageBox::Warning,"警告","没有工程,请新建工程！");
        //box.setStandardButtons (QMessageBox::Ok|QMessageBox::Cancel);
        box.setStandardButtons (QMessageBox::Ok);
        box.setButtonText (QMessageBox::Ok,QString("确 定"));
        box.setButtonText (QMessageBox::Cancel,QString("取 消"));
        box.exec();
        return;
    }
    //QString item = QInputDialog::getItem(this, tr("打开工程"),
    //                                     tr("请选择要打开的工程:"), items, 0, false, &ok);
    QString item = MSGINF::MsgGetItem(this,_("Open Project"),_("Select Open Project Please!"),items,&ok);
    if (ok && !item.isEmpty()){

        emit ClearRunTable();

        m_enable = false;

        shapeItems.clear();
        update();

        m_ProjectName = item;
        m_LayerName = "default";
        //this->parentWidget()->setWindowTitle(m_ProjectName+"-"+m_LayerName);
        emit SetTitle(m_ProjectName,m_LayerName);

        newPictureButton->setEnabled(true);
        newSquareButton->setEnabled(true);
        newDeleteButton->setEnabled(true);
        newSaveButton->setEnabled(true);
        newLayerButton->setEnabled(true);

        qDebug()<< rds[item.toStdString()].c_str();

        std::string strkey,strJson;
        strkey = item.toLocal8Bit().data();
        strJson = rds[strkey];

        openJson(strJson);

    }

}

void SortingBox::openJson(std::string strJson)
{
    /*
    circlePath.addRect(QRect(0, 0, 400, 300));

    squarePath.addRect(QRect(0, 0, 160, 60));
    squarePath.moveTo(0 ,30);
    squarePath.lineTo(160, 30);s
    squarePath.moveTo(80 ,30);
    squarePath.lineTo(80, 60);
    */
    int P1x,P1y,P2x,P2y,tp;
    neb::CJsonObject cjs,ndcjs;
    std::string str;
    if(cjs.Parse(strJson)){
        for(int i=0;i<cjs["shape"].GetArraySize();i++){
            ndcjs.Clear();
            cjs["shape"].Get(i,ndcjs);
            ndcjs.Get("P1_x",P1x);
            ndcjs.Get("P1_y",P1y);
            ndcjs.Get("P2_x",P2x);
            ndcjs.Get("P2_y",P2y);
            ndcjs.Get("type",tp);
            if(tp == E_NORMAL){
                ndcjs.Get("point",str);
            }
            else
                ndcjs.Get("pic",str);

            ShapeItem shapeItem;
            if(tp == E_NORMAL){
                shapeItem.setPath(squarePath);
                shapeItem.setToolTip(QString(str.c_str()));
                shapeItem.setPoint(QString(str.c_str()));
            }
            else{
                shapeItem.setPath(circlePath);
                shapeItem.setToolTip("Pic");
                //shapeItem.setPic(QString(str.c_str()));
                shapeItem.setPic( QString::fromLocal8Bit(str.c_str()));
                ///
                QPixmap pixPP = QPixmap(((ShapeItem)shapeItem).getPic());
                QPainterPath picRect;
                picRect.addRect(QRect(0, 0,
                                      pixPP.width()>800?800:pixPP.width(),
                                      pixPP.height()>600?600:pixPP.height()));
                if(!pixPP.isNull())
                    shapeItem.setPath(picRect);
                ///


            }
            QPoint P1,P2;
            P1 = QPoint(P1x,P1y);
            P2 = QPoint(P2x,P2y);


            shapeItem.setPosition(P1);

            //QPoint tmp =  QPoint(-15,15);
            shapeItem.setArrowPosition(P2);
            QColor color = initialItemColor();// QColor::fromRgb(0,255,0);

            shapeItem.setColor(color);

            shapeItem.setShapType((Shaptype)tp);

            shapeItems.append(shapeItem);

        }
    }
}

void SortingBox::createNewCreate()
{
    /*
QInputDialog* inputDialog=new QInputDialog(this);
inputDialog->setWindowTitle("提示");
inputDialog->setLabelText("姓名：");
inputDialog->setOkButtonText("确定");
inputDialog->setCancelButtonText("取消");
bool ok;
if(inputDialog->exec()==QDialog::Accepted){
    ok=true;
}else{
    ok=false;
}
QString text=inputDialog->textValue();
     */

    bool ok;
    QString qsql;
    std::string sql;
    QString text=QInputDialog::getText(this,tr("新建工程"),tr("请输入新建工程名称："),QLineEdit::Normal,"",&ok);
    if(ok && !text.isEmpty()){
        qsql = QString("select value from fsapp where value = '%1'").arg(text);
        RECORDSET rd = m_Sql->RecordSet(qsql.toStdString());
        if(rd.size()>0){
            QMessageBox box(QMessageBox::Warning,"警告","工程名已存！");
            //box.setStandardButtons (QMessageBox::Ok|QMessageBox::Cancel);
            box.setStandardButtons (QMessageBox::Ok);
            box.setButtonText (QMessageBox::Ok,QString("确 定"));
            box.setButtonText (QMessageBox::Cancel,QString("取 消"));
            box.exec();
        }
        else{
            qsql = QString("insert into fsapp(value) values('%1')").arg(text);
            m_Sql->exeSql(qsql.toStdString());
            qsql = QString("insert into fslayer(value,fsapp) values('default','%1')").arg(text);
            m_Sql->exeSql(qsql.toStdString());
            shapeItems.clear();

            m_ProjectName = text;
            m_LayerName = "default";
            this->parentWidget()->setWindowTitle(m_ProjectName+"-"+m_LayerName);

            newPictureButton->setEnabled(true);
            newSquareButton->setEnabled(true);
            newDeleteButton->setEnabled(true);
            newSaveButton->setEnabled(true);
            newLayerButton->setEnabled(true);
        }

    }

    update();


}
//! [17]
int SortingBox::itemAt(const QPoint &pos)
{
    for (int i = shapeItems.size() - 1; i >= 0; --i) {
        const ShapeItem &item = shapeItems[i];
        shapeItems[i].setArrowLeftDown(-1);

        if(item.ArrowRect().contains(pos - item.position())){
            shapeItems[i].setArrowLeftDown(i);
            this->setCursor(QCursor(Qt::SizeAllCursor));
            return i;
        }

        if (item.path().contains(pos - item.position())){

            return i;
        }


    }
    return -1;
}
//! [17]

//! [18]
void SortingBox::moveItemTo(const QPoint &pos)
{
    QPoint offset = pos - previousPosition;
    if(itemInMotion->getArrowLeftDown()>= 0){
        itemInMotion->setArrowPosition(itemInMotion->arrowPosition()+offset);
    }
    else{
        itemInMotion->setPosition(itemInMotion->position() + offset);
    }
//! [18] //! [19]
    previousPosition = pos;
    update();
}
//! [19]

//! [20]
//!
//!
int SortingBox::updateButtonGeometryX(QToolButton *button, int x,int y)
{
    //int margin = style()->pixelMetric(QStyle::PM_DefaultTopLevelMargin);
    QSize size = button->sizeHint();
    button->setGeometry(x,y,
                        size.rwidth(), size.rheight());

    return x + size.rheight() +10;
           //- style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing);
}

int SortingBox::updateButtonGeometry(QToolButton *button, int x, int y)
{
    QSize size = button->sizeHint();
    button->setGeometry(x - size.rwidth(), y - size.rheight(),
                        size.rwidth(), size.rheight());

    return y - size.rheight()
           - style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing);
}
//! [20]

//! [21]
void SortingBox::createShapeItem(const QPainterPath &path,
                                 const QString &toolTip, const QPoint &pos,
                                 const QColor &color,Shaptype sp)
{
    QDir dir;
    QString currentPath=dir.currentPath();
    currentPath += "/images/car.png";

    ShapeItem shapeItem;
    shapeItem.setPath(path);
    shapeItem.setToolTip(toolTip);
    shapeItem.setPosition(pos);

    QPoint tmp =  QPoint(-15,15);
    shapeItem.setArrowPosition(tmp);

    shapeItem.setColor(color);

    shapeItem.setShapType(sp);
    if(sp == E_BITMAP){

        QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
                                                         "./",
                                                        tr("Images (*.png *.bmp)"));
        if(!fileName.isEmpty()){
            shapeItem.setPic(fileName);
            QPixmap pixPP = QPixmap(((ShapeItem)shapeItem).getPic());
            QPainterPath picRect;
            picRect.addRect(QRect(0, 0,
                                  pixPP.width()>800?800:pixPP.width(),
                                  pixPP.height()>600?600:pixPP.height()));
            shapeItem.setPath(picRect);
        }
        else
            return;
    }
    else
    {
        QString pinLabel = createPin();
        if(pinLabel != "")
            shapeItem.setPoint(pinLabel);
        else
            return;
    }
    shapeItems.append(shapeItem);
    update();
}
//! [21]

//! [22]
QToolButton *SortingBox::createToolButton(const QString &toolTip,
                                          const QIcon &icon, const char *member)
{
    QToolButton *button = new QToolButton(this);
    //button->setEnabled(false);
    button->setToolTip(toolTip);
    button->setIcon(icon);
    button->setIconSize(QSize(24, 24));
    connect(button, SIGNAL(clicked()), this, member);

    return button;
}
//! [22]

//! [23]
QPoint SortingBox::initialItemPosition(const QPainterPath &path)
{
    int x;
    int y = (height() - qRound(path.controlPointRect().height()) / 2);
    if (shapeItems.size() == 0)
        x = ((3 * width()) / 2 - qRound(path.controlPointRect().width())) / 2;
    else
        x = (width() / shapeItems.size()
             - qRound(path.controlPointRect().width())) / 2;

    return QPoint(x, y);
}
//! [23]

//! [24]
QPoint SortingBox::randomItemPosition()
{
    return QPoint(QRandomGenerator::global()->bounded(width() - 120), QRandomGenerator::global()->bounded(height() - 120));
}
//! [24]

//! [25]
QColor SortingBox::initialItemColor()
{
    //return QColor::fromHsv(((shapeItems.size() + 1) * 85) % 256, 255, 190);
    //return QColorConstants::Svg::darkseagreen;// QColor::fromRgb(0,255,0);
    return QColor::fromRgb(110,200,255);

}
//! [25]

//! [26]
QColor SortingBox::randomItemColor()
{
    //return QColor::fromHsv(QRandomGenerator::global()->bounded(256), 255, 190);
    //return QColorConstants::Svg::darkseagreen;// QColor::fromRgb(0,255,0);
    //return QColor::fromRgb(0xF5,0xF5,0xDC);
    return QColor::fromRgb(110,200,255);
}
//! [26]

void SortingBox::region(const QPoint &cursorGlobalPoint)
{
    QRect rect ;//= this->rect();

    QPoint tl;// = mapToGlobal(rect.topLeft());
    QPoint rb;// = mapToGlobal(rect.bottomRight());

    int idx = itemAt(cursorGlobalPoint);


    //QPoint GlobalPoint = mapToGlobal(cursorGlobalPoint);
    int x ;//= cursorGlobalPoint.x();
    int y ;//= cursorGlobalPoint.y();

    if(idx >=0 ){
        if(shapeItems[idx].getShapType() == E_BITMAP)
        {
            rect = shapeItems[idx].path().controlPointRect().toRect();
        }
        if(shapeItems[idx].getArrowLeftDown()>=0){
            mDirec = NONE;
            return;
        }
    }
    else{
        mDirec = NONE;
        this->setCursor(QCursor(Qt::ArrowCursor));
        return;
    }
/*
    tl = mapToGlobal(rect.topLeft());
    rb = mapToGlobal(rect.bottomRight());
    tl = mapToParent(rect.topLeft());
    rb = mapToParent(rect.bottomRight());
*/
    tl = rect.topLeft();
    rb = rect.bottomRight();

    QPoint GlobalPoint = cursorGlobalPoint-shapeItems[idx].position();
    x = GlobalPoint.x();
    y = GlobalPoint.y();



    if(tl.x() + PADDING_TOP >= x && tl.x() <= x && tl.y() + PADDING_TOP >= y && tl.y() <= y) {
        // 左上角
        mDirec = LEFTTOP;
        this->setCursor(QCursor(Qt::SizeFDiagCursor));
    } else if(x >= rb.x() - PADDING && x <= rb.x() && y >= rb.y() - PADDING && y <= rb.y()) {
        // 右下角
        mDirec = RIGHTBOTTOM;
        this->setCursor(QCursor(Qt::SizeFDiagCursor));
    } else if(x <= tl.x() + PADDING && x >= tl.x() && y >= rb.y() - PADDING && y <= rb.y()) {
        //左下角
        mDirec = LEFTBOTTOM;
        this->setCursor(QCursor(Qt::SizeBDiagCursor));
    } else if(x <= rb.x() && x >= rb.x() - PADDING && y >= tl.y() && y <= tl.y() + PADDING) {
        // 右上角
        mDirec = RIGHTTOP;
        this->setCursor(QCursor(Qt::SizeBDiagCursor));
    }
    else if(x <= tl.x() + PADDING && x >= tl.x()) {
        // 左边
        mDirec = LEFT;
        this->setCursor(QCursor(Qt::SizeHorCursor));
    } else if( x <= rb.x() && x >= rb.x() - PADDING) {
        // 右边
        mDirec = RIGHT;
        this->setCursor(QCursor(Qt::SizeHorCursor));
    }else if(y >= tl.y() && y <= tl.y() + PADDING_TOP){
        // 上边
        mDirec = UP;
        this->setCursor(QCursor(Qt::SizeVerCursor));
    } else if(y <= rb.y() && y >= rb.y() - PADDING) {
        // 下边
        mDirec = DOWN;
        this->setCursor(QCursor(Qt::SizeVerCursor));
    }else {
        // 默认
        mDirec = NONE;
        this->setCursor(QCursor(Qt::ArrowCursor));
    }
}
void SortingBox::myRunning(bool r)
{
    qDebug()<<"myRunning = " << r;
    m_enable = r;
    //if(m_ProjectName.isEmpty())
    //    return;
    setButtonEnable(!r);
}
void SortingBox::setButtonShow(bool r)
{
    if(r){
        newLayerButton->show();
        newPictureButton->show();
        newSquareButton->show();
        newDeleteButton->show();
        newSaveButton->show();
        //newCreateButton->show();
        newOpenButton->show();
    }
    else{
        newLayerButton->hide();
        newPictureButton->hide();
        newSquareButton->hide();
        newDeleteButton->hide();
        newSaveButton->hide();
        //newCreateButton->show();
        newOpenButton->hide();

    }
}
void SortingBox::setButtonEnable(bool r)
{
    //newLayerButton->setEnabled(r);

    //newPictureButton->setEnabled(r);
    //newSquareButton->setEnabled(r);
    //newDeleteButton->setEnabled(r);
    //newSaveButton->setEnabled(r);
    newCreateButton->setEnabled(r);
    newOpenButton->setEnabled(r);
}
void SortingBox::CreateLayerButton()
{
    newLayerButton = new QToolButton(this);
    //button->setEnabled(false);
    newLayerButton->setToolTip("Layer");
    newLayerButton->setIcon(QIcon(":/images/Layers.png"));
    newLayerButton->setIconSize(QSize(24, 24));
    //newLayerButton->setArrowType(Qt::UpArrow);
    //connect(newLayerButton, &QAction::triggered, this, &SortingBox::addLayer);

    QAction *pAction = new QAction(this);
    pAction->setText("Add layer");
    pAction->setIcon(QIcon(":/images/Create.png"));
    connect(pAction, &QAction::triggered, this, &SortingBox::addLayer);

    QAction *pActionSelect = new QAction(this);
    pActionSelect->setText("Select layer");
    pActionSelect->setIcon(QIcon("://images/Selection.png"));
    connect(pActionSelect, &QAction::triggered, this, &SortingBox::selectLayer);

    QMenu* menu = new QMenu();
    //menu->addAction(pAction);
    menu->addAction(pActionSelect);
    newLayerButton->setPopupMode(QToolButton::InstantPopup );
    newLayerButton->setMenu(menu);

}
void SortingBox::addLayer()
{
    bool ok;
    QString qsql;
    std::string sql;
    QString text=QInputDialog::getText(this,tr("新建图层"),tr("请输入图层名称："),QLineEdit::Normal,"",&ok);
    if(ok && !text.isEmpty()){
        qsql = QString("select value from fslayer where value = '%1' and fsapp = '%2'").arg(text).arg(m_ProjectName);
        RECORDSET rd = m_Sql->RecordSet(qsql.toStdString());
        if(rd.size()>0){
            QMessageBox box(QMessageBox::Warning,"警告","图层名已存！");
            //box.setStandardButtons (QMessageBox::Ok|QMessageBox::Cancel);
            box.setStandardButtons (QMessageBox::Ok);
            box.setButtonText (QMessageBox::Ok,QString("确 定"));
            box.setButtonText (QMessageBox::Cancel,QString("取 消"));
            box.exec();
        }
        else{
            qsql = QString("insert into fslayer(value,fsapp) values('%1','%2')").arg(text).arg(m_ProjectName);;
            m_Sql->exeSql(qsql.toStdString());
            shapeItems.clear();

            //m_ProjectName = text;
            m_LayerName = text;
            this->parentWidget()->setWindowTitle(m_ProjectName+"-"+m_LayerName);

        }

    }

    update();
}

void SortingBox::selectLayer()
{
    bool ok = false;
    QStringList items;
    NODE nd;
    NODE rds;
    QString qsql;
    std::string value;
    items << tr("Spring") << tr("Summer") << tr("Fall") << tr("Winter");
    items.clear();
    qsql = QString("select b.* from fslayer b where b.fsapp = '%1'").arg(m_ProjectName);
    RECORDSET rd = m_Sql->RecordSet(qsql.toStdString());

    if(rd.size()>0){
        for(RECORDSET::iterator it = rd.begin();it!=rd.end();it++){
        //for(int i = 0;i<rd.size();i++){
            nd =  *it;
            value = nd["value"];
            items << QString::fromLocal8Bit(value.c_str());
            rds[value] = nd["para"];
            qDebug() << QString::fromLocal8Bit(value.c_str());
        }
    }
    else{
        //QMessageBox box(QMessageBox::Warning,"警告","没有图层！");
        //box.setStandardButtons (QMessageBox::Ok|QMessageBox::Cancel);
        //box.setStandardButtons (QMessageBox::Ok);
        //box.setButtonText (QMessageBox::Ok,QString("确 定"));
        //box.setButtonText (QMessageBox::Cancel,QString("取 消"));
        //box.exec();
        MSGINF::MsgShowOk(this,_("Warning"),_("Layer Is Empty."));
        return;
    }
    //QString item = QInputDialog::getItem(this, tr("选择图层"),
    //                                     tr("请选择要打开的图层:"), items, 0, false, &ok);

     QString item = MSGINF::MsgGetItem(this,_("Select Layer"),_("Select Project Layer Please!"),items,&ok);

    if (ok && !item.isEmpty()){

        shapeItems.clear();
        update();

        //m_ProjectName = item;
        m_LayerName = item;
        //this->parentWidget()->setWindowTitle(m_ProjectName+"-"+m_LayerName);
        emit SetTitle(m_ProjectName,m_LayerName);

        qDebug()<< rds[item.toStdString()].c_str();

        std::string strkey,strJson;
        strkey = item.toLocal8Bit().data();
        strJson = rds[strkey];

        openJson(strJson);
    }
}
void SortingBox::RefresItem()
{
    QString sql;//m_ProjectName;
    //QString m_LayerName;
    sql = QString("select * from fsapp value = '%1'").arg(m_ProjectName);
    RECORDSET rd = m_Sql->RecordSet(sql.toStdString());

    if(rd.size()<=0){
        m_ProjectName="";
        m_LayerName ="";
        shapeItems.clear();
        newPictureButton->setEnabled(false);
        newSquareButton->setEnabled(false);
        newDeleteButton->setEnabled(false);
        newSaveButton->setEnabled(false);
        newLayerButton->setEnabled(false);
    }
    sql = QString("select * from fslayer value = '%1'").arg(m_LayerName);
    rd = m_Sql->RecordSet(sql.toStdString());
    if(rd.size()<=0){
        m_LayerName ="";
        shapeItems.clear();
        newPictureButton->setEnabled(false);
        newSquareButton->setEnabled(false);
        newDeleteButton->setEnabled(false);
        newSaveButton->setEnabled(false);
        newLayerButton->setEnabled(false);
    }


    update();
}

QString SortingBox::createPin()
{
    QString ret = "",sql;
    bool ok = false;
    QStringList items;
    NODE nd;
    NODE rds;
    std::string value;
    items << tr("Spring") << tr("Summer") << tr("Fall") << tr("Winter");
    items.clear();
    sql = QString("select * from fspoint where layer = '%1' and fsapp = '%2'")
            .arg(m_LayerName)
            .arg(m_ProjectName);
    RECORDSET rd = m_Sql->RecordSet(sql.toStdString());

    if(rd.size()>0){
        for(RECORDSET::iterator it = rd.begin();it!=rd.end();it++){
        //for(int i = 0;i<rd.size();i++){
            nd =  *it;
            value = nd["id"];
            items << QString::fromLocal8Bit(value.c_str());

        }
    }
    else{
        //QMessageBox box(QMessageBox::Warning,"警告","没有测量点，请在参数设置先添加测量点信息！");
        //box.setStandardButtons (QMessageBox::Ok|QMessageBox::Cancel);
        //box.setStandardButtons (QMessageBox::Ok);
        //box.setButtonText (QMessageBox::Ok,QString("确 定"));
        //box.setButtonText (QMessageBox::Cancel,QString("取 消"));
        //box.exec();
        MSGINF::MsgShowOk(this,_("Warning"),_("Measure Is Empty,Project First Add Measure Please."));
        return "";
    }
    //QString item = QInputDialog::getItem(this, tr("测量点"),
    //                                      tr("请选择测量点:"), items, 0, false, &ok);
    QString item = MSGINF::MsgGetItem(this,_("Select Measure"),_("Measure"),items,&ok);

    if (ok && !item.isEmpty()){
        ret = item;
        //
        for (const ShapeItem &shapeI : qAsConst(shapeItems)) {
            if(((ShapeItem)shapeI).getPoint()==item){
                MSGINF::MsgShowOk(this,_("Warning"),_("Measure Already Exist,Select Other Measure Please."));
                ret = "";
                break;
            }
        }
        //

    }



    return ret;
}

void SortingBox::OnboxShowPin(QString strPic,QString strPin)
{
    //qDebug()<< __FUNCTION__ << strPic << strPin;
    static QString stPic = "";

    itemInMotion=nullptr;
    m_enable = true;

    if(stPic != strPic){
        this->RefresItem();
        stPic = strPic;
    }

    QStringList list1 = strPic.split(';');
    for(int i=0;i<list1.size();i++)
        FindAndShow(E_BITMAP,list1.at(i).toStdString());
    FindAndShow(E_NORMAL,strPin.toStdString());

    update();
}


void SortingBox::FindAndShow(Shaptype type,std::string json)
{
    int P1x,P1y,P2x,P2y,tp;
    neb::CJsonObject ndcjs;
    std::string str;
    if(ndcjs.Parse(json)){


            ndcjs.Get("P1_x",P1x);
            ndcjs.Get("P1_y",P1y);
            ndcjs.Get("P2_x",P2x);
            ndcjs.Get("P2_y",P2y);
            ndcjs.Get("type",tp);
            if(tp == E_NORMAL){
                ndcjs.Get("point",str);
            }
            else
                ndcjs.Get("pic",str);


            for (const ShapeItem &shapeI : qAsConst(shapeItems)) {
                if(type == E_BITMAP){
                    if(((ShapeItem)shapeI).getPic().toStdString()==str){
                        return;
                    }
                }
                else if(type == E_NORMAL){
                    if(((ShapeItem)shapeI).getPoint().toStdString()==str){
                        return;
                    }
                }
            }
                //


            ShapeItem shapeItem;
            if(tp == E_NORMAL){
                shapeItem.setPath(squarePath);
                shapeItem.setToolTip(QString(str.c_str()));
                shapeItem.setPoint(QString(str.c_str()));
            }
            else if(type == E_BITMAP){
                shapeItem.setPath(circlePath);
                shapeItem.setToolTip("Pic");
                shapeItem.setPic(QString(str.c_str()));
                ///
                QPixmap pixPP = QPixmap(((ShapeItem)shapeItem).getPic());
                QPainterPath picRect;
                picRect.addRect(QRect(0, 0,
                                      pixPP.width()>800?800:pixPP.width(),
                                      pixPP.height()>600?600:pixPP.height()));
                if(!pixPP.isNull())
                    shapeItem.setPath(picRect);
                ///


            }
            QPoint P1,P2;
            P1 = QPoint(P1x,P1y);
            P2 = QPoint(P2x,P2y);


            shapeItem.setPosition(P1);

            //QPoint tmp =  QPoint(-15,15);
            shapeItem.setArrowPosition(P2);
            QColor color = initialItemColor();// QColor::fromRgb(0,255,0);

            shapeItem.setColor(color);

            shapeItem.setShapType((Shaptype)tp);

            shapeItems.append(shapeItem);


    }
}
/*
绿：rgb(62, 188, 55)
红：rgb(210, 32, 28)
黄：rgb(255, 242, 34)
*/
void SortingBox::OnShowGapFlush(QString pin,QString gap, QString flush,int flag)
{
    qDebug()<< __FUNCTION__<< pin << gap << flush << flag;

    for (int i = shapeItems.size() - 1; i >= 0; --i) {
        const ShapeItem &item = shapeItems[i];

        if(((ShapeItem)item).getPoint() == pin){

            shapeItems[i].setGap(gap);
            shapeItems[i].setFlush(flush);
            //if(flag==0){
            //    shapeItems[i].setGapColor(Qt::black);
            //    shapeItems[i].setFlushColor(Qt::black);
            //}
            //Set Color..
            //shapeItems[i].setGapColor(Qt::yellow);
            shapeItems[i].setGapColor(QColor::fromRgb(255, 242, 34));
            if((flag&0x100) ==0x100){
                //shapeItems[i].setFlushColor(Qt::green);
                shapeItems[i].setGapColor(QColor::fromRgb(62, 188, 55));
            }
            else if((flag&0x200) ==0x0200){
                //shapeItems[i].setFlushColor(Qt::red);
                shapeItems[i].setGapColor(QColor::fromRgb(210, 32, 28));
            }
            //
            //shapeItems[i].setFlushColor(Qt::yellow);
            shapeItems[i].setFlushColor(QColor::fromRgb(255, 242, 34));
            if((flag&0x1)==0x1){
                //shapeItems[i].setFlushColor(Qt::green);
                shapeItems[i].setFlushColor(QColor::fromRgb(62, 188, 55));
            }
            else if((flag&0x2)==0x2){
                //shapeItems[i].setFlushColor(Qt::red);
                shapeItems[i].setFlushColor(QColor::fromRgb(210, 32, 28));
            }
            //Nothing value
            if(gap == "-"){
                shapeItems[i].setGapColor(Qt::gray);
            }
            if(flush == "-"){
                shapeItems[i].setFlushColor(Qt::gray);
            }
            //shapeItems[i].setArrowLeftDown(i);
            break;
        }

    }
    update();
}
void SortingBox::OnSetTitle(QString prj,QString layer)
{
    QString title = QString("%1:%2 %3:%4").arg(_("Project"),m_ProjectName,_("Layer"),m_LayerName);
    this->parentWidget()->setWindowTitle(title);
}
void SortingBox::OnSetEnable(bool bf)
{
    m_enable = bf;
}
void SortingBox::test()
{
    QLibrary mylib("log");
    if(mylib.load())
    {
        qDebug() << "dllhook加载成功:";
        LogIni = (exported_proc_logini)mylib.resolve("Ini");
        ShowLog = (exported_proc_log)mylib.resolve("ShowLog");
        if(LogIni){
            LogIni(".");
            ShowLog("dllhook加载成功:");
        }

        //SetKeyBoardHook open = (SetKeyBoardHook)mylib.resolve("SetKeyBoardHook");
        //if(open)
        //{
         //   qDebug() << "SetKeyBoardHook加载成功";
         //   bool flag = open((HWND)this->winId());
        //}
    }
}


